﻿using System;
using System.Windows.Forms;
using Syncfusion.Windows.Forms;

using PMngr.Data;

namespace PMngr.Main
{
    public partial class LoginForm : Office2007Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void BtnOkClick(object sender, EventArgs e)
        {
            var principal = new PMPrincipal(txtUser.Text, txtPassword.Text);
            
            txtPassword.Text = "";
            if ((!principal.Identity.IsAuthenticated))
            {
                // The profile is still not validated. 
                MessageFactory.Show(Utilities.PasswordError);
                System.Threading.Thread.CurrentPrincipal = principal;
            }
            else
            {
                // Update the current principal. 
                System.Threading.Thread.CurrentPrincipal = principal;
                DialogResult = DialogResult.OK;
            }
        }

        private void BtnCancelClick(object sender, EventArgs e)
        {
            Close();
        }
    }
}
